import { defineConfig } from "@solidjs/start/config";
import UnoCSS from "unocss/vite";

const mobile = !!/android|ios/.exec(process.env.TAURI_ENV_PLATFORM as string);

const host = process.env.TAURI_DEV_HOST;

let hmrPort = 5183;

export default defineConfig({
  ssr: false,
  server: {
    preset: "static",
  },
  vite: {
    plugins: [UnoCSS()],
    server: {
      host: mobile ? "0.0.0.0" : false, // listen on all addresses
      port: 1420,
      strictPort: true,
      hmr: mobile
        ? {
          protocol: "ws",
          host,
          port: hmrPort++,
        }
        : undefined,
      watch: {
        // 2. tell vite to ignore watching `src-tauri`
        ignored: ["**/src-tauri/**"],
      },
    },
    // 3. to make use of `TAURI_DEBUG` and other env variables
    // https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
    envPrefix: ["VITE_", "TAURI_"],
  }
});
